cmake_minimum_required(VERSION 3.15)


project("LearnOpenGL")

## 指定语法标准
set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 项目路径参数
set(_PRJ_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}")
set(_PRJ_3RDPARTY_DIR "${_PRJ_ROOT_DIR}/3rdparty")
set(_PRJ_TARGET_DIR "${_PRJ_ROOT_DIR}/target")
set(CMAKE_INSTALL_PREFIX "${_PRJ_ROOT_DIR}/target")

if (MSVC)
    set(GLFW3_DIR "${_PRJ_3RDPARTY_DIR}/glfw/v3.3")
    set(GLFW3_INCLUDE_DIRS "${GLFW3_DIR}/include")
    set(GLFW3_LIBRARY_DIR "${GLFW3_DIR}/libs/vc2017/lib")
    set(GLFW3_LIBRARIES "glfw3")

    set(GLAD_DIR "${_PRJ_TARGET_DIR}/glad")
    set(GLAD_INCLUDE_DIRS "${GLAD_DIR}/include")
    set(GLAD_LIBRARY_DIR "${GLAD_DIR}/lib")
    set(GLAD_LIBRARIES "glad")

    # 适用环境变量指定的Qt版本
    if (EXISTS $ENV{QT5_DIR})
        message("环境变量QT5_DIR存在!")
        find_package(Qt5 COMPONENTS Core Widgets Network OpenGL REQUIRED)
    else ()
        message(FATAL_ERROR "环境变量QT5_DIR不存在,无法编译该项目")
    endif ()

endif ()


add_subdirectory("3rdparty/glad")

# 自动添加子工程
file(GLOB ChildrenDirs "src/*") # 获取目标路径下的内容,深度为1
foreach (aChildDir ${ChildrenDirs})
    message("----> ${aChildDir}")
    if(NOT EXISTS "${aChildDir}/CMakeLists.txt")
        message(WARNING "**** ${aChildDir} **** 该目录已被忽略,原因是它可能不是有效的CMake项目文件夹!")
    else ()
        add_subdirectory("${aChildDir}")
    endif ()
endforeach ()
